<?php

namespace common\entities\myhtsq;

use common\entities\ContractEntity;
use common\entities\myhtsq\ApplicationPriceEntity;
use Yii;

/**
 * This is the model class for table "myscrm_application_info".
 *
 * @property string $application_id
 * @property string $unique_name
 * @property string $application_name
 * @property integer $authorization_type
 * @property string $created_on
 * @property string $created_by
 * @property string $modified_on
 * @property string $modified_by
 */
class ApplicationInfoEntity extends ContractEntity
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'myscrm_application_info';
    }

    public static function globalTableName()
    {
        preg_match("/dbname=([^;]+)/i", self::getDb()->dsn, $matches);
        return $matches[1].'.myscrm_application_info';
    }



    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['application_id'], 'required'],
            [['authorization_type'], 'integer'],
            [['created_on', 'modified_on'], 'safe'],
            [['application_id', 'created_by', 'modified_by'], 'string', 'max' => 36],
            [['unique_name'], 'string', 'max' => 30],
            [['application_name'], 'string', 'max' => 100]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'application_id' => '产品ID',
            'unique_name' => '产品编号',
            'application_name' => '产品名称',
            'authorization_type' => '授权类型',
            'created_on' => '创建时间',
            'created_by' => '创建人',
            'modified_on' => '修改时间',
            'modified_by' => '修改人',
        ];
    }

    /**
     * 获取产品的关联价格
     *
     * @return \yii\db\ActiveQuery
     */
    public function getPrice()
    {
        return $this->hasOne(ApplicationPriceEntity::className(), ['application_id' => 'application_id']);
    }

}
